package cn.mugutu.finance.domain.system;

import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * 系统用户
 */
@Entity
@Table(name = "sys_user")
@Data
public class User extends BaseEntity {
    private static final long serialVersionUID = 1L;

    private String username;
    private String realname;
    private String password;
    private boolean locked;    //是否锁定
    private String loginIp;
    private String lastLoginIp;    //上次登录ip
    private Date loginDate;
    private Date lastLoginDate;    //上次登录时间
    private Date createDate;

    @ManyToOne
    @JoinColumn(name = "departmentId")
    private Department department;

    //角色列表
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "sys_user_role",
            joinColumns = {@JoinColumn(name = "user_id")},
            inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private Set<Role> roles = new HashSet<Role>();


}
